package wen.recommend.servlet.admin;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import wen.recommend.dao.UserDao;

/*
 * 管理员登录的servlet
 */
public class AdminLoginServlet extends HttpServlet {

	UserDao userDao = new UserDao();

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request,response);

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		request.setCharacterEncoding("UTF-8");
		String adminName = request.getParameter("adminname");
		String adminPass = request.getParameter("password");
		boolean isSucc = userDao.validateAdmin(adminName,adminPass);
		if(isSucc){
			request.getSession().setAttribute("loginAdmin", adminName);
			response.sendRedirect("/booksRecommend/adminIndex");
		}else{
			response.setContentType("text/html;charset=utf-8");
			response.getWriter().write("<SCRIPT>alert('用户名或密码不正确！');history.back();</SCRIPT>");

	}
  }

}
